{% extends "shuup/admin/base_small_dialog.jinja" %}
{% block title %}{% trans %}Login{% endtrans %}{% endblock %}
{% from "shuup/admin/macros/general.jinja" import auth_block %}
{% block content %}
    {% call auth_block() %}
        <form action="{{ request.path }}" method="post" id="login_form">
            <div class="auth-body">
                <div class="auth-heading pt-3 pb-3 text-center">
                    <h1 class="h1">{% trans %}Welcome back{% endtrans %}</h1>
                    {% csrf_token %}
                    {% if error %}
                        <p class="mb-0">{{ error|striptags }}</p>
                    {% endif %}
                    {% if form.non_field_errors() %}
                        <div class="auth-alert d-flex alert alert-warning alert-dismissable fade show align-items-start" role="alert">
                            {% for error in form.non_field_errors() %}
                                <p class="mb-0"><i class="fa fa-warning mr-2"></i>{{ error }}</p>
                            {% endfor %}
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                    {% endif %}
                </div>
                {{ bs3.field(form.username) }}
                {{ bs3.field(form.password) }}
                <a class="mt-2 d-inline-block text-muted" href="{{ url("shuup_admin:request_password") }}">
                    {% trans %}Forgot your password?{% endtrans %}
                </a>
                <input type="hidden" name="next" value="{{ next }}">
                <div class="actions">
                    <button class="mt-4 btn btn-primary btn-lg btn-block" type="submit">
                        <i class="fa fa-sign-in"></i>
                        {% trans %}Login{% endtrans %}
                    </button>
                </div>
            </div>
        </form>
    {% endcall %}
{% endblock %}
{% block extra_js %}
<script>
$(function () {
    $("#login_form").on("submit", function() {
        var loginBtn = $(this).find('.btn-primary');
        loginBtn
            .removeClass('btn-primary')
            .addClass('btn-default')
            .empty()
            .append($('<div class="loader-spinner"></div>'));
    });
});
</script>
{% endblock %}
